package com.nbsaas.boot.project.rest.convert;

import com.nbsaas.boot.project.api.domain.simple.ProjectTaskSimple;
import com.nbsaas.boot.project.data.entity.ProjectTask;
import com.nbsaas.boot.rest.api.Converter;

/**
 * 项目任务-列表对象转换器
 */

public class ProjectTaskSimpleConvert implements Converter<ProjectTaskSimple, ProjectTask> {


    @Override
    public ProjectTaskSimple convert(ProjectTask source) {
        ProjectTaskSimple result = new ProjectTaskSimple();

        result.setNote(source.getNote());

        try {
            if (source.getCreator() != null) {
                result.setCreator(source.getCreator().getId());
            }
        } catch (Exception ignored) {
        }

        result.setAddress(source.getAddress());
        result.setLng(source.getLng());

        try {
            if (source.getCreator() != null) {
                result.setCreatorName(source.getCreator().getName());
            }
        } catch (Exception ignored) {
        }


        try {
            if (source.getProject() != null) {
                result.setProject(source.getProject().getId());
            }
        } catch (Exception ignored) {
        }

        result.setPriority(source.getPriority());
        result.setAddDate(source.getAddDate());

        try {
            if (source.getEntry() != null) {
                result.setEntry(source.getEntry().getId());
            }
        } catch (Exception ignored) {
        }

        result.setBeginDate(source.getBeginDate());

        try {
            if (source.getExecutor() != null) {
                result.setExecutorName(source.getExecutor().getName());
            }
        } catch (Exception ignored) {
        }


        try {
            if (source.getExecutor() != null) {
                result.setExecutor(source.getExecutor().getId());
            }
        } catch (Exception ignored) {
        }

        result.setName(source.getName());
        if (source.getState() != null) {
            result.setStateName(String.valueOf(source.getState()));
        }
        result.setState(source.getState());
        result.setId(source.getId());

        try {
            if (source.getProject() != null) {
                result.setProjectName(source.getProject().getName());
            }
        } catch (Exception ignored) {
        }

        result.setDeadline(source.getDeadline());
        result.setLat(source.getLat());
        result.setLastDate(source.getLastDate());


        return result;
    }

}